package com.purchase.ml.mapper.prod;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.purchase.ml.bean.req.dealer.DealerProdEditDto;
import com.purchase.ml.bean.req.dealer.DealerProdQueryDto;
import com.purchase.ml.bean.req.prod.SysProdQueryDto;
import com.purchase.ml.bean.req.sys.SysUserQueryDto;
import com.purchase.ml.bean.res.prod.SysProdRes;
import com.purchase.ml.bean.res.prod.SysShopProdRes;
import com.purchase.ml.bean.res.sys.SysRes;
import com.purchase.ml.entity.prod.SysCategory;
import com.purchase.ml.entity.prod.SysProduct;
import com.purchase.ml.entity.prod.SysProductSku;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author :zxm
 * @date :2021/2/25 18:57
 * @description :some description
 **/

@Mapper
@Repository
public interface SysProdMapper extends BaseMapper<SysProduct> {

    /**
     * 分页查询主经销商产品
     * @param dto
     * @return
     */
    List<SysProdRes> selectProdPages(@Param("dto") DealerProdQueryDto dto);

    /**
     * 根据经销商id查询所有的商品
     * @param dealerId
     * @return
     */
    List<Long> selectProdIds(@Param("state") Integer state,@Param("dealerId") Long dealerId);

//    Long selectCount(@Param("dto") DealerProdQueryDto dto);

    /**
     * 修改主经销商产品状态
     * @param
     * @return
     */
    int updateDealerProd(@Param("dto") DealerProdEditDto dto,@Param("dealerId") Long dealerId);

    /**
     * 通过商品id查询出商品
     * @param productId
     * @return
     */
    SysProduct selectProductByProductId(@Param("productId") Long productId);

    /**
     * 修改产品状态
     * @param id
     * @return
     */
    @Update("update sys_product set state=#{state} where id=#{id}")
    int updateProdState(@Param("id") Long id,@Param("state") Integer state);

    @Select("select count(*) from sys_product where category_id=#{categoryId} ")
    Long selectCountByCategoryId(@Param("categoryId") Long categoryId);

    /**
     * 查询商户对应状态下的商品
     * @param state
     * @param dealerId
     * @return
     */
    @Select("select product_id from sys_dealer_pruduct where dealer_id=#{dealerId} and `state`=#{state} ")
    List<Long> selectProdIdsState(@Param("state") Integer state, @Param("dealerId") Long dealerId);

    /**
     * 系统商店商品分页
     * @return
     */
    List<SysShopProdRes> selectShopProdPages(@Param("dto") SysProdQueryDto dto);

    /**
     * 主经销商商店商品分页
     * @param dto
     * @return
     */
    List<SysShopProdRes> selectDealerProductPage(@Param("dto") SysProdQueryDto dto);
}
